<html>
<head><meta charset="utf-8"><title>architecture · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html">architecture</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246269140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246269140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246269140">(Jul 16 2021 at 19:39)</a>:</h4>
<p>Is there a high-level overview of the way clippy works laying around anywhere?</p>



<a name="246269339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246269339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246269339">(Jul 16 2021 at 19:41)</a>:</h4>
<p>As in, everything from parsing to type-checking and the driver itself. I'm looking at how feasible it would be to create a custom linter and wanted to look at how clippy works in general.</p>



<a name="246271921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246271921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246271921">(Jul 16 2021 at 20:05)</a>:</h4>
<blockquote>
<p>a custom linter</p>
</blockquote>
<p>Like, for specific Rust libraries, or... (I'm asking about the former in <a class="stream-topic" data-stream-id="257328" href="/#narrow/stream/257328-clippy/topic/SNAFU-specific.20lints">#clippy &gt; SNAFU-specific lints</a> )</p>



<a name="246272128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246272128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246272128">(Jul 16 2021 at 20:07)</a>:</h4>
<p>My thought was to create something roughly similar to clippy, but with wasm dylibs that are provided by anyone. The lint wouldn't necessarily be for a given library, but that would of course be a major use case.</p>



<a name="246272260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246272260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246272260">(Jul 16 2021 at 20:08)</a>:</h4>
<p>I'm aware that the AST isn't guaranteed, but I would like to <em>try</em> to get something stable-ish that can be converted bidirectionally as necessary. That's not particularly relevant to my question, though.</p>



<a name="246273153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273153">(Jul 16 2021 at 20:17)</a>:</h4>
<p>ah, yes, Wasm. I always forget about that.</p>



<a name="246273259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273259">(Jul 16 2021 at 20:18)</a>:</h4>
<p>There was <a href="https://github.com/trailofbits/dylint">https://github.com/trailofbits/dylint</a></p>



<a name="246273477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273477">(Jul 16 2021 at 20:20)</a>:</h4>
<p>I saw that, ironically the day <em>after</em> I thought of this. Imo the problem with that is the inflexibility and weight of it (spawning any number of drivers). I'd prefer to have a nicer API anyways, which isn't really possible without creating one separately.</p>



<a name="246273561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273561">(Jul 16 2021 at 20:21)</a>:</h4>
<p>Though I suppose I could dig into that to see how they extracted various things from clippy. I just wasn't sure if there was an architectural overview of clippy itself somewhere that I wasn't aware of.</p>



<a name="246273627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273627">(Jul 16 2021 at 20:22)</a>:</h4>
<p>well, let me know if you make something that enables writing library-specific lints <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="246273712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246273712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246273712">(Jul 16 2021 at 20:23)</a>:</h4>
<p>Will do! I was drafting up an API for how diagnostics could be emitted in a general way yesterday.</p>



<a name="246275381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246275381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246275381">(Jul 16 2021 at 20:37)</a>:</h4>
<p>You might be interested in <a href="https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/">https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/</a></p>



<a name="246275637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246275637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246275637">(Jul 16 2021 at 20:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/257328-clippy/topic/architecture/near/246275381">said</a>:</p>
<blockquote>
<p>You might be interested in <a href="https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/">https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/</a></p>
</blockquote>
<p>Already commented <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="246277304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246277304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246277304">(Jul 16 2021 at 20:55)</a>:</h4>
<p>Oh this looks kind of neat<br>
<a href="https://github.com/trailofbits/dylint">https://github.com/trailofbits/dylint</a></p>



<a name="246277610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246277610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246277610">(Jul 16 2021 at 20:58)</a>:</h4>
<p>Now picture that without having to spawn multiple drivers and with a cleaner API :)</p>



<a name="246310721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246310721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246310721">(Jul 17 2021 at 07:26)</a>:</h4>
<p>A pretty minimalistic custom linter, that functions kind of like clippy is <a href="https://github.com/nbdd0121/klint">klint</a> from the Rust-for-Linux project. This is just a prototype at the moment and not used in production.</p>
<p>Since in the last 2 weeks I talked with various people about custom lints / linters, I thought about if it were helpful to provide a linter template, that you can quickly set up with <code>cargo generate</code> (or similar). </p>
<hr>
<p>For your question on how Clippy works:</p>
<ul>
<li>There is <code>clippy-driver</code>, which uses the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/struct.RunCompiler.html">RunCompiler</a> API of rustc_driver. Lints are registered with the <code>callbacks</code> field of this struct.</li>
<li>Then there is <code>cargo-clippy</code>, which is just the cargo wrapper for the driver. This mostly just does additional argument handling for the part behind <code>--</code> in <code>cargo clippy -- &lt;here&gt;</code> and calls the <code>clippy-driver</code> programmatically</li>
<li>How lints work is closely tied to the highly unstable API of rustc itself. You can think of it, that Clippy runs rustc and just uses the AST/HIR/MIR, that rustc produced. So for example to get the type of an expression, rustc analyses the crate and Clippy then asks rustc for the type with <code>cx.tcx.expr_ty(expr)</code>. (This is no 100% accurate, but a good mental model for it IMO)</li>
<li>Clippy has many helper functions in <code>clippy_utils</code>. We don't want to publish <code>clippy_utils</code> on <a href="http://crates.io">crates.io</a>, since this is just as unstable as rustc itself. But if more people write custom lint tools and want to see helper functions from <code>clippy_utils</code> uplifted into rustc, this is definitely something that can be done.</li>
</ul>



<a name="246310993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246310993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246310993">(Jul 17 2021 at 07:34)</a>:</h4>
<p>klint looks like a good place for me to start, as it's quite straightforward as to what it's doing (hooking into the compiler and all). My main problem will definitely be getting a stable interface that can be bidirectionally converted. I can easily see how I could convert klint to something pluggable, though.<br>
Thanks for the info. It's certainly not an easy topic to dive into.</p>



<a name="246311139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246311139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246311139">(Jul 17 2021 at 07:38)</a>:</h4>
<p>How much desire is there for custom lints anyways? dylint just happened to pop up right when I was thinking about it, and I could picture a number of crates providing their own lints.</p>



<a name="246311313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246311313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246311313">(Jul 17 2021 at 07:42)</a>:</h4>
<p>I think the need for custom linters will get more important over time. As I said, this topic came up 3 or 4 times for me in the past 2 weeks. So I would be willing to help work on making writing custom linters / lints easy.</p>



<a name="246312443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246312443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246312443">(Jul 17 2021 at 08:08)</a>:</h4>
<p>Non-exhaustive list of problems I see right now:</p>
<ol>
<li>To set up your linter, you have to write a considerable amount of boilerplate code.</li>
<li>You have to hook into <code>#[feature(rustc_private)]</code> and by extent you have to use a nightly toolchain to use your linter.</li>
<li>You have to use completely unstable rustc APIs that are subject to change on a daily basis.</li>
<li>... And probably more, that I don't think of, since I never wrote a custom linter from scratch.</li>
</ol>
<hr>
<p>How this could be addressed:</p>
<ol>
<li>This could be easily addressed by providing a template, where you then just have to fill in the linting code</li>
<li>You could circumvent this by using <code>RUSTC_BOOTSTRAP=1</code> and could use any toolchain you like. You would still be bound to one toolchain and updating to a new toolchain will be a PITA, because of 3.</li>
<li>Making any compiler internals stable seems impossible to me. Even providing a stable API for custom linters seems impossible. This would just make improving the compiler way more difficult. So the only thing I can see here is a stable-ish  API for analysis queries. But I have no idea where to start here. Also much of linting is matching on the AST / HIR directly without calling queries, which is really hard to provide a stable-ish API for.</li>
</ol>
<hr>
<p><span class="user-mention" data-user-id="222148">@Felix Kohlgrüber</span> wrote his master thesis about this topic, which may be a starting point: <a href="https://github.com/rust-lang/rust-clippy/issues/3875">rust-clippy#3875</a></p>



<a name="246312717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246312717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246312717">(Jul 17 2021 at 08:15)</a>:</h4>
<p><a href="https://github.com/fkohlgrueber/pattern-matching">https://github.com/fkohlgrueber/pattern-matching</a></p>



<a name="246312974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246312974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246312974">(Jul 17 2021 at 08:23)</a>:</h4>
<ol>
<li>This actually wouldn't be the case as I'm planning on having dynamically loadable wasm libraries. As such, the only code needed to be written by the lint author would be the lint itself (and some metadata).</li>
<li>Using internal APIs is absolutely a must, barring reimplementing literally everything from scratch. It wouldn't be difficult to provide binaries to the end users, so using nightly shouldn't in and of itself be an issue.</li>
<li>We wouldn't need to stabilize the internals, "just" something that can be converted to and from the internals. No doubt still a difficult task, but certainly easier than stabilizing the internals itself. The internal structure would only need to be updated as necessary, given that the various crates would be compiled into the final binary (with end users not caring about it at all). I know there's work on creating a formal grammar for Rust, which would help with the AST side of things. I also plan on looking into <code>syn</code> for a potential starting point for an AST.</li>
</ol>
<p>This is unquestionably an enormous project that will take significant time and effort. I'll certainly look over the links you've provided when I have time. Right now I'm still trying to organize the thoughts in my head in addition to finding others that may be interested in collaborating to an extent. No idea if this is something a project group might be good for, but the API design will presumably be the most difficult challenge.</p>



<a name="246313442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246313442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246313442">(Jul 17 2021 at 08:34)</a>:</h4>
<p>Ah, I think I now understand what your plan is. I'm definitely willing to collaborate in this project.  This is an interesting and difficult project. So if you want to bounce ideas, let me know!</p>



<a name="246314002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246314002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246314002">(Jul 17 2021 at 08:49)</a>:</h4>
<p>Writing things out is probably step one! I'll create a repository where issues can be filed and whatnot at some point. Quite busy tomorrow (and likely thru Tuesday), but we'll see. I'll definitely let you and <span class="user-mention" data-user-id="116155">@Jake Goulding</span> know when things happen.</p>



<a name="246314197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246314197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246314197">(Jul 17 2021 at 08:55)</a>:</h4>
<p>One final thing before I finally go to sleep, what I'm thinking of is glue code, to put a term to it.</p>



<a name="246424378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246424378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xFrednet <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246424378">(Jul 19 2021 at 07:33)</a>:</h4>
<p>Hey, I've just caught up with the discussion and I would also be happy to help out <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="246424776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246424776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246424776">(Jul 19 2021 at 07:39)</a>:</h4>
<p>Awesome! I'll probably draft something up Tuesday evening and put it out on IRLO on Wednesday, assuming everything in the meantime goes well (other priorities).</p>



<a name="246520522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246520522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246520522">(Jul 19 2021 at 21:57)</a>:</h4>
<p>Should this be a project group? I see there's a template repository under the rust-lang GitHub. The primary focus would realistically be creating a stable API to act as glue code between end users and the various rustc crates. This would unlock user-provided lints with relative ease. There's other use cases as well to say the least.</p>



<a name="246554886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/246554886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#246554886">(Jul 20 2021 at 07:51)</a>:</h4>
<p>We could start a project group for it. But I'm not too worried about under which name or orga structure we work on this project.</p>



<a name="247276315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247276315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Disconnect3d <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247276315">(Jul 26 2021 at 23:23)</a>:</h4>
<p>Yay, I just found this. Disclaimer: I work for Trail of Bits who developed dylint and and we do write custom lints</p>



<a name="247276343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247276343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Disconnect3d <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247276343">(Jul 26 2021 at 23:23)</a>:</h4>
<p>regarding how clippy works, I know this was answered but this may also give some insight or fill some gaps (?): <a href="https://www.trailofbits.com/post/write-rust-lints-without-forking-clippy">https://www.trailofbits.com/post/write-rust-lints-without-forking-clippy</a></p>



<a name="247283110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247283110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247283110">(Jul 27 2021 at 01:21)</a>:</h4>
<p>Feel free to have trail of bits pitch in with regard to this effort! I created a GitHub org for those that are interested.</p>



<a name="247319369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247319369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247319369">(Jul 27 2021 at 11:09)</a>:</h4>
<p>I've actually been messing around with this too as sort of tangential to my GSoC project. <span class="user-mention" data-user-id="245610">@Jacob Pratt</span> do you have a link to this org?</p>
<p>The things I've come up with are:</p>
<ol>
<li>To allow downstream crates (users of your lib that have specific lints) to use the lints from a tool without doing a bunch of work I went with including the wasm bytes in the original lib with a "magically" named static <code>__PLUGIN_BYTES</code> or something similar. This would be under a feature flag so it doesn't add to binary size.</li>
<li>The linter program checks each dylib for this static and registers the lints if found by loading the dynamic lib and then running the wasm bytes found.</li>
</ol>
<p>I haven't gotten as far as designing the linter, although I was probably planning on using rust analyzer internals. I started a proof of concept <a href="https://github.com/DevinR528/ruma-check">https://github.com/DevinR528/ruma-check</a> and I also experimented with a <code>Visitor</code> trait using rust analyzers <code>ast</code> types <a href="https://github.com/DevinR528/ruma-check/blob/visit/src/visit.rs">https://github.com/DevinR528/ruma-check/blob/visit/src/visit.rs</a> (even more experimental and not close to done). I just realized this would need a <code>Early/LateContext</code> thing for all the methods too.</p>



<a name="247325730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247325730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Disconnect3d <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247325730">(Jul 27 2021 at 12:25)</a>:</h4>
<p>Just to be sure, is the thing you want to build a way for projects to develop &amp; run their own lints? Or is it about an easier &amp; (hopefully) stable way to match patterns? Or both?</p>



<a name="247326415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247326415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247326415">(Jul 27 2021 at 12:31)</a>:</h4>
<p>It's mostly about providing a stable API to the compiler internals. This API may or may not include something that makes it easier for projects to write their own lints. We're still figuring things out.</p>



<a name="247360736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247360736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247360736">(Jul 27 2021 at 16:58)</a>:</h4>
<p>My end goal is to provide a custom linter. The stable API is a necessary prerequisite to attain the type of linter I'm imagining.</p>



<a name="247360787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247360787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247360787">(Jul 27 2021 at 16:59)</a>:</h4>
<p><span class="user-mention" data-user-id="243877">@DevinR528</span> the org is rust-linting. Nothing there yet. Would you like me to invite you to it?</p>



<a name="247360818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247360818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247360818">(Jul 27 2021 at 16:59)</a>:</h4>
<p>Yes please!</p>



<a name="247360866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247360866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247360866">(Jul 27 2021 at 16:59)</a>:</h4>
<p>What's your GitHub?</p>



<a name="247361079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247361079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247361079">(Jul 27 2021 at 17:00)</a>:</h4>
<p><a href="https://github.com/DevinR528">https://github.com/DevinR528</a></p>



<a name="247361316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247361316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Disconnect3d <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247361316">(Jul 27 2021 at 17:02)</a>:</h4>
<p><span class="user-mention" data-user-id="245610">@Jacob Pratt</span> Custom linter, or, a lint? Also, why not Dylint?</p>



<a name="247361401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247361401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247361401">(Jul 27 2021 at 17:02)</a>:</h4>
<p>Custom linter, not just a single lint. There's a post on IRLO I made regarding this if you're interested.</p>



<a name="247361645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247361645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Disconnect3d <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247361645">(Jul 27 2021 at 17:04)</a>:</h4>
<p>I guess its this one: <a href="https://internals.rust-lang.org/t/towards-a-stable-compiler-api-and-custom-lints/15048">https://internals.rust-lang.org/t/towards-a-stable-compiler-api-and-custom-lints/15048</a> ; will check it out ;)</p>



<a name="247361878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/architecture/near/247361878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/architecture.html#247361878">(Jul 27 2021 at 17:06)</a>:</h4>
<p>Correct</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>